using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace SurveyHost.Core.DAL
{
	/// <summary>
	/// Strongly-typed collection for the AnswerObjectType class.
	/// </summary>
	[Serializable]
	public partial class AnswerObjectTypeCollection : ActiveList<AnswerObjectType, AnswerObjectTypeCollection> 
	{	   
		public AnswerObjectTypeCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the AnswerObjectType table.
	/// </summary>
	[Serializable]
	public partial class AnswerObjectType : ActiveRecord<AnswerObjectType>
	{
		#region .ctors and Default Settings
		
		public AnswerObjectType()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AnswerObjectType(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AnswerObjectType(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AnswerObjectType(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("AnswerObjectType", TableType.Table, DataService.GetInstance("SurveyHost"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAnswerTypeName = new TableSchema.TableColumn(schema);
				colvarAnswerTypeName.ColumnName = "AnswerTypeName";
				colvarAnswerTypeName.DataType = DbType.String;
				colvarAnswerTypeName.MaxLength = 100;
				colvarAnswerTypeName.AutoIncrement = false;
				colvarAnswerTypeName.IsNullable = false;
				colvarAnswerTypeName.IsPrimaryKey = true;
				colvarAnswerTypeName.IsForeignKey = false;
				colvarAnswerTypeName.IsReadOnly = false;
				colvarAnswerTypeName.DefaultSetting = @"";
				colvarAnswerTypeName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAnswerTypeName);
				
				TableSchema.TableColumn colvarAssemblyQualifiedName = new TableSchema.TableColumn(schema);
				colvarAssemblyQualifiedName.ColumnName = "AssemblyQualifiedName";
				colvarAssemblyQualifiedName.DataType = DbType.String;
				colvarAssemblyQualifiedName.MaxLength = 250;
				colvarAssemblyQualifiedName.AutoIncrement = false;
				colvarAssemblyQualifiedName.IsNullable = false;
				colvarAssemblyQualifiedName.IsPrimaryKey = false;
				colvarAssemblyQualifiedName.IsForeignKey = false;
				colvarAssemblyQualifiedName.IsReadOnly = false;
				colvarAssemblyQualifiedName.DefaultSetting = @"";
				colvarAssemblyQualifiedName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAssemblyQualifiedName);
				
				TableSchema.TableColumn colvarAnswerConfigurationHelpText = new TableSchema.TableColumn(schema);
				colvarAnswerConfigurationHelpText.ColumnName = "AnswerConfigurationHelpText";
				colvarAnswerConfigurationHelpText.DataType = DbType.String;
				colvarAnswerConfigurationHelpText.MaxLength = 1000;
				colvarAnswerConfigurationHelpText.AutoIncrement = false;
				colvarAnswerConfigurationHelpText.IsNullable = false;
				colvarAnswerConfigurationHelpText.IsPrimaryKey = false;
				colvarAnswerConfigurationHelpText.IsForeignKey = false;
				colvarAnswerConfigurationHelpText.IsReadOnly = false;
				colvarAnswerConfigurationHelpText.DefaultSetting = @"";
				colvarAnswerConfigurationHelpText.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAnswerConfigurationHelpText);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["SurveyHost"].AddSchema("AnswerObjectType",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AnswerTypeName")]
		public string AnswerTypeName 
		{
			get { return GetColumnValue<string>("AnswerTypeName"); }

			set { SetColumnValue("AnswerTypeName", value); }

		}

		  
		[XmlAttribute("AssemblyQualifiedName")]
		public string AssemblyQualifiedName 
		{
			get { return GetColumnValue<string>("AssemblyQualifiedName"); }

			set { SetColumnValue("AssemblyQualifiedName", value); }

		}

		  
		[XmlAttribute("AnswerConfigurationHelpText")]
		public string AnswerConfigurationHelpText 
		{
			get { return GetColumnValue<string>("AnswerConfigurationHelpText"); }

			set { SetColumnValue("AnswerConfigurationHelpText", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
				
		private SurveyHost.Core.DAL.MeasureCollection colMeasureRecords;
		public SurveyHost.Core.DAL.MeasureCollection MeasureRecords
		{
			get
			{
				if(colMeasureRecords == null)
					colMeasureRecords = new SurveyHost.Core.DAL.MeasureCollection().Where(Measure.Columns.DefaultAnswerTypeName, AnswerTypeName).Load();
				return colMeasureRecords;			
			}

			set { colMeasureRecords = value; }

		}

				
		private SurveyHost.Core.DAL.StemCollection colStemRecords;
		public SurveyHost.Core.DAL.StemCollection StemRecords
		{
			get
			{
				if(colStemRecords == null)
					colStemRecords = new SurveyHost.Core.DAL.StemCollection().Where(Stem.Columns.AnswerTypeName, AnswerTypeName).Load();
				return colStemRecords;			
			}

			set { colStemRecords = value; }

		}

		
		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varAnswerTypeName,string varAssemblyQualifiedName,string varAnswerConfigurationHelpText)
		{
			AnswerObjectType item = new AnswerObjectType();
			
			item.AnswerTypeName = varAnswerTypeName;
			
			item.AssemblyQualifiedName = varAssemblyQualifiedName;
			
			item.AnswerConfigurationHelpText = varAnswerConfigurationHelpText;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varAnswerTypeName,string varAssemblyQualifiedName,string varAnswerConfigurationHelpText)
		{
			AnswerObjectType item = new AnswerObjectType();
			
				item.AnswerTypeName = varAnswerTypeName;
				
				item.AssemblyQualifiedName = varAssemblyQualifiedName;
				
				item.AnswerConfigurationHelpText = varAnswerConfigurationHelpText;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AnswerTypeName = @"AnswerTypeName";
			 public static string AssemblyQualifiedName = @"AssemblyQualifiedName";
			 public static string AnswerConfigurationHelpText = @"AnswerConfigurationHelpText";
						
		}

		#endregion
	}

}

